package com.lintf.starter.myService;

import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@ConditionalOnProperty(
        name = "my.starter.enabled", // 配置属性名
        havingValue = "true" // 属性值为 true 时生效
)
@ConditionalOnClass(MyService.class) // 类路径存在时生效
@EnableConfigurationProperties(MyProperties.class) // 启用配置属性
public class MyAutoConfiguration {

    @Bean
    @ConditionalOnMissingBean // 没有实例时创建
    public MyService myService(MyProperties properties) {
        return new MyService(properties.getPrefix());
    }
}